<?php

use think\migration\Migrator;
use think\migration\db\Column;

class CreateShopGoodsSkuPriceTable extends Migrator
{
    /**
     * Migrate Up.
     */
    public function up()
    {
        $table = $this->table('shop_goods_sku_price', ['comment' => '商品规格价格', 'engine' => 'InnoDB', 'collation' => 'utf8mb4_general_ci']);
        $table->addColumn('goods_sku_ids', 'string', ['limit'  =>  120, 'null' => true, 'default' => null, 'comment' => '规格'])
            ->addColumn('goods_sku_text', 'string', ['limit' => 255, 'null' => true, 'default' => null, 'comment' => '规格中文'])
            ->addColumn('goods_id', 'integer', ['limit'  =>  11, 'default' => 0, 'comment' => '商品'])
            ->addColumn('image', 'string', ['limit' => 255, 'null' => true, 'default' => null, 'comment' => '缩略图'])
            ->addColumn('stock', 'integer', ['limit'  =>  10, 'default' => 0, 'comment' => '库存'])
            ->addColumn('stock_warning', 'integer', ['limit'  =>  10, 'null' => true, 'default' => null, 'comment' => '库存预警'])
            ->addColumn('sales', 'integer', ['limit'  =>  10, 'default' => 0, 'comment' => '销量'])
            ->addColumn('sn', 'string', ['limit'  =>  50, 'null' => true, 'default' => null, 'comment' => '货号'])
            ->addColumn('weight', 'decimal', ['precision' => 10, 'scale' => 2, 'default' => 0, 'comment' => '重量(KG)'])
            ->addColumn('cost_price', 'decimal', ['precision' => 10, 'scale' => 2, 'null' => true, 'default' => null, 'comment' => '成本价'])
            ->addColumn('original_price', 'decimal', ['precision' => 10, 'scale' => 2, 'null' => true, 'default' => null, 'comment' => '原价'])
            ->addColumn('price', 'decimal', ['precision' => 10, 'scale' => 2, 'null' => true, 'default' => null, 'comment' => '价格'])
            ->addColumn(Column::enum('status', ['up', 'down'])->setDefault('up')->setComment('商品状态:up=上架,down=下架'))
            ->addColumn('weigh', 'integer', ['limit'  =>  8, 'default' => 0, 'comment' => '权重'])
            ->addColumn('create_time', 'integer', ['limit'  =>  10, 'null' => true, 'default' => null, 'comment' => '创建时间'])
            ->addColumn('update_time', 'integer', ['limit'  => 10, 'null' => true, 'default' => null, 'comment' => '更新时间'])
            ->create();
    }

    /**
     * Migrate Down.
     */
    public function down()
    {
        $table = $this->table('shop_goods_sku_price');
        $table->drop();
    }
}
